local longdan = fk.CreateSkill {

  name = "joy_mou__longdan",

  tags = {  },

}



longdan:addEffect("viewas", {
  name = "joy_mou__longdan",
  pattern = ".|.|.|.|.|basic",
  prompt = "#joy_mou__longdan",
  interaction = function(self,player)
    local names = {}
    for _, id in ipairs(Fk:getAllCardIds()) do
      local card = Fk:getCardById(id)
      if card.type == Card.TypeBasic and not card.is_derived and
        ((Fk.currentResponsePattern == nil and card.skill:canUse(player, card)) or
        (Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(card))) then
        table.insertIfNeed(names, card.name)
      end
    end
    if #names == 0 then return end
    return UI.ComboBox {choices = names}
  end,
  card_filter = function(self, player, to_select, selected)
    if #selected == 0 then
      return Fk:getCardById(to_select).type == Card.TypeBasic
    end
    if #selected == 1 then return false end
  end,
  view_as = function(self, player,cards)
    if not self.interaction.data then return end
    if #cards ~= 1 then return end
    if not table.find(cards, function(id) return Fk:getCardById(id).type == Card.TypeBasic end) then return end
    local card = Fk:cloneCard(self.interaction.data)
    card:addSubcards(cards)
    card.skillName = longdan.name
    return card
  end,
  before_use = function(self, player, use)
    player.room:removePlayerMark(player,"@joy_mou__longdan",1)
    if not player.dead then
      player:drawCards(1, longdan.name)
    end
  end,
  enabled_at_play = function(self, player)
    return player:getMark("@joy_mou__longdan") > 0 
  end,
  enabled_at_response = function(self, player, response)
    return player:getMark("@joy_mou__longdan") > 0 
  end,
})

longdan:addEffect(fk.GameStart, {
  name = "#joy_mou__longdan_trigger",
  anim_type = "offensive",
  events = {fk.GameStart,fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
      return player:hasSkill(longdan.name) and player:getMark("@joy_mou__longdan") < 3
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
      if player:getMark("@joy_mou__longdan") < 3 and not player.dead then
        player.room:addPlayerMark(player,"@joy_mou__longdan",1)
      end
  end
})
longdan:addEffect(fk.TurnEnd, {
  name = "#joy_mou__longdan_trigger",
  anim_type = "offensive",
  events = {fk.GameStart,fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
      return player:hasSkill(longdan.name) and player:getMark("@joy_mou__longdan") < 3
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
      if player:getMark("@joy_mou__longdan") < 3 and not player.dead then
        player.room:addPlayerMark(player,"@joy_mou__longdan",1)
      end
  end
})

return longdan